package ita.mock.servlet;

import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

/**
 * Servlet implementation class DataServlet
 */
public class DataServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static Logger logger=Logger.getLogger(DataServlet.class);    
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DataServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//		String num=request.getParameter("num");
//		logger.debug("some debugs...");
//		PrintWriter writer=response.getWriter();
//		writer.write("Hello,I wait you "+num);
		doSth(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doSth(request,response);
	}

	private void doSth(HttpServletRequest request, HttpServletResponse response) throws IOException {
		String num=request.getParameter("num");
		OutputStream os=response.getOutputStream();
		System.out.println("dataservlet");
		os.write(("hello"+num).getBytes());
	}
}
